﻿using GalaSoft.MvvmLight.Helpers;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using GalaSoft.MvvmLight;
using System.Collections.Generic;
using System;
using TestApp.Model;
using TestApp.Model.Managers;
using TestApp.Navigation;
using TestApp.Messages;
using TestApp.ViewModel.UIControlsViewModel;
using TestApp.Resources;

namespace TestApp.ViewModel
{
    public class PlanningViewModel : ViewModelBase, IHomeBaseViewModel, IDynamicDataTemplate
    {
        // Property Names
        private const string SelectedIndexProperty = "SelectedIndex";
        
        //  Tiles
        public List<TileItem> Tiles
        {
            get;
            set;
        }

        // Tile Tapped
        public RelayCommand<Int32> OnSelectionChanged
        {
            get;
            set;
        }

        // Title
        public String Title
        {
            get
            {
                return LocalizedStrings.PlanningPivot;
            }
        }

        // Data Template
        public String DataTemplate
        {
            get
            {
                return @"PlanningViewTemplate";
            }
        }

        // Selected Items
        public Int32 SelectedIndex
        {
            get
            {
                return -1;
            }
        }

        // Navigation Service
        private INavigationService NavigationService;

        public PlanningViewModel(INavigationService navigationService) 
        {
            Tiles = new List<TileItem>()
            {
                new TileItem()
                {
                    ImageUri = GraphicResources.Weekly_Specials_Icon,
                    Title = LocalizedStrings.WeeklySpecialsTile,
                    Notification = LocalizedStrings.WeeklySpecialsNotification,
                    Message = LocalizedStrings.WeeklySpecialsMessage,
                    GroupTag = LocalizedStrings.HubTileGroupTag,
                    Background = GraphicResources.Weekly_Specials_Background

                },
                new TileItem()
                {
                    ImageUri = GraphicResources.Coupons_Icon,
                    Title = LocalizedStrings.CouponsTile,
                    Notification = LocalizedStrings.CouponsNotification,
                    Message = LocalizedStrings.CouponsMessage,
                    GroupTag = LocalizedStrings.HubTileGroupTag,
                    Background = GraphicResources.Coupons_Background
                },
                new TileItem()
                {
                    ImageUri = GraphicResources.ShoppingList_Icon,
                    Title = LocalizedStrings.ShoppingListTile,
                    Notification = LocalizedStrings.ShoppingListNotification,
                    Message = LocalizedStrings.ShoopingListMessage,
                    GroupTag = LocalizedStrings.HubTileGroupTag,
                    Background = GraphicResources.Shopping_List_Background
                },
                new TileItem()
                {
                    ImageUri = GraphicResources.Recipes_Icon,
                    Title = LocalizedStrings.RecipesTile,
                    Notification = LocalizedStrings.RecipesNotification,
                    Message = LocalizedStrings.RecipesMessage,
                    GroupTag = LocalizedStrings.HubTileGroupTag,
                    Background = GraphicResources.Recipes_Background
                },
                new TileItem()
                {
                    ImageUri = GraphicResources.Store_Icon,
                    Title = LocalizedStrings.StoreLocatorTile,
                    Notification = LocalizedStrings.StoreLocatorNotification,
                    Message = LocalizedStrings.StoreLocatorMessage,
                    GroupTag = LocalizedStrings.HubTileGroupTag,
                    Background = GraphicResources.Store_Background
                }
            };

            OnSelectionChanged = new RelayCommand<Int32>(TileTapped);

            NavigationService = navigationService;
        }

        private void TileTapped(Int32 tileIndex)
        {
            if (tileIndex == 1)
            {
                NavigationService.NavigateTo(ViewModelLocator.CouponsListPage);
            }
            else if (tileIndex == 4)
            {
                NavigationService.NavigateTo(ViewModelLocator.StoresPage);
            }
            RaisePropertyChanged(SelectedIndexProperty);
        }
    }
}
